package com.quarkus.resource;

import com.quarkus.bean.Country;
import com.quarkus.bean.MultipartBody;
import com.quarkus.client.CountriesService;
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;

@Path("country")
public class TestRestClientResource {

    @RestClient
    @Inject
    CountriesService countriesService;

    @GET
    @Path("{name}")
    @Produces(MediaType.APPLICATION_JSON)
    public Country getByName(@PathParam("name") String name, @HeaderParam("Content-Type") String contentType){
        System.out.println(contentType);
        return countriesService.getByName(name);
    }

//    @GET
//    @Path("{name}")
//    @Produces(MediaType.APPLICATION_JSON)
//    public CompletionStage<Country> getByName(@PathParam("name") String name, @HeaderParam("Content-Type") String contentType) throws ExecutionException, InterruptedException {
//        System.out.println(contentType);
//        return countriesService.getByName2(name);
//    }

//    @GET
//    @Path("{name}")
//    @Produces(MediaType.APPLICATION_JSON)
//    public Uni<Country> getByName(@PathParam("name") String name, @HeaderParam("Content-Type") String contentType) throws ExecutionException, InterruptedException {
//        System.out.println(contentType);
//        return countriesService.getByName3(name);
//    }

    @POST
    @Path("/multipart")
    @Produces(MediaType.TEXT_PLAIN)
    public String sendFile() throws Exception {
        MultipartBody body = new MultipartBody();
        body.fileName = "greeting.txt";
        body.file = new ByteArrayInputStream("HELLO WORLD".getBytes(StandardCharsets.UTF_8));
        return countriesService.sendMultipartData(body);
    }
}
